<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>添加管理员</title>
<meta name="author" content="DeathGhost" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/style.css" />
<script src="<%=request.getContextPath()%>/resources/js/jquery.js"></script>
<script src="<%=request.getContextPath()%>/resources/js/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.validate.js"></script>
<script>
	$(function(){
		//回显
		var roleIds = '${roleIds}';
		$("input[name='roleIds']").each(function(){
			var value = $(this).val();
			if(roleIds.indexOf(value) >= 0){
				$(this).attr("checked",true);
			}
		});
		
		$("#form").validate({
			rules: {
				rePassword: {
					equalTo: "#password"
				}
			},
			messages: {
				rePassword: {
					equalTo: "<span class='errorTips'>两次密码不一致</span>"
				}
			},
            submitHandler: function (form) {
            	$.ajax({
        			url: "${empty admin?'save':'update' }.do",
        			data: $("#form").serialize(),
        			type: "post",
        			success: function(data){
        				if (data) {
	 						layer.msg('操作成功！');
	 					} else {
	 						layer.msg('操作失败！');
	 					}
        			}
        		});
            }
		});
	});
</script>
</head>
<body>
	<!--header-->
	<jsp:include page="../common/header.jsp"></jsp:include>

	<section>
		<div class="rt_content">
			<p>&nbsp;</p>
			<form id="form" method="post">
				<input type="hidden" name="id" value="${admin.id }">
				<table class="table">
					<tr>
						<td>
							管理员: 
						</td>
						<td>
							<input type="text"  name="name" size="30" value="${admin.name }"/>
						</td>
					</tr>
					<tr>
						<td>
							密码: 
						</td>
						<td>
							<input type="password" id="password"  name="password" size="30"/>
						</td>
					</tr>
					<tr>
						<td>
							确认密码: 
						</td>
						<td>
							<input type="password" name="rePassword" size="30"/>
						</td>
					</tr>
					<tr>
						<td>
							角色: 
						</td>
						<td>
							<span class="fieldSet">
								<c:forEach items="${roles }" var="one">
									<label>
										<input type="checkbox" name="roleIds" value="${one.id }"/>${one.name }
									</label>
								</c:forEach>
							</span>
						</td>
					</tr>
					
					<tr>
						<td colspan="2" align="center">
							<input type="submit" name="提交" />
							<input type="reset" name="重置" />
						</td>
					</tr>
				</table>
			</form>
		</div>
	</section>
</body>
</html>

